package com.yyw.controller.scurity;

import com.alibaba.fastjson.JSON;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName MyAuthenticationErrorHandel
 * @Description TODO
 * @Author YiYuWei
 * @Date 2020/7/1 23:39
 * @Version 1.0
 */
public class MyAuthenticationErrorHandel implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        Map<String,Object> map = new HashMap<>();
        map.put("error",true);
        String s = JSON.toJSONString(map);
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(s);
    }
}
